*! version 2.0
* 21 August 2013
* NIDS 
* Reshaping the mortality section of the household questionnaire
	* Data is in wide format in questionnaires.
	* Can be useful for it to be in long format for analysis purposes.

*=====================================================================================================================================
* GLOBALS FOR DATA FILES AND VERSION SUFFIXES

* This do file will only reshape Wave 2 mortality as it allows for cause of death.

global DataIN "\\137.158.104.21\data\Panel Public Release 2014a\Wave 2\Anon"
global DataOUT "C:\Users\01406074\Desktop"
global VersionIN "W2_Anon_V2.2"
global VersionOUT "merged"
																		
version 12.0													// version of Stata being used, this is needed for the rename command.

*=====================================================================================================================================

* OPENING THE HOUSEHOLD QUESTIONNAIRE DATA, KEEPING RELEVANT VARIABLES AND RESHAPING THE MORTALITY SECTION

use "$DataIN\HHQuestionnaire_$VersionIN.dta", clear					// opening HHQ

rename w2_h_* *
keep if  outcome == 1												// keeping households that were successfully interviewed
keep if  mrt24mnth == 1												// keeping households that had a death in the past 24 months 

keep  w2_hhid mrtgen1 -  mrtpid6									// keeping the relevant variables

forvalues x = 1/6 {													// renaming the mortality cause other
cap rename mrtcau`x'_o mrtcau_o`x'
}

reshape long  mrtgen mrtr mrtdod_m mrtdod_y mrtage  ///
mrtcau mrtcau_o mrtpid, i(w2_hhid) j(mort) string					// reshaping the mortality section to long format
destring mort, replace												// destringing mort number

drop if  mrtgen == .												// dropping empty records
order  mrtcau_o, after( mrtcau)										// moving the other mort cause after mort cause

* labeling the variables
label var 	mort "Number of deceased person"
label var	mrtgen	"c3 - What the deceased's gender?"
label var	mrtr	"c4 - Relationship of deceased to Household Head"
label var	mrtdod_m	"c5_m - Date of death for person 1 - month only"
label var	mrtdod_y	"c5_y - Date of death for person 1 - year only"
label var	mrtage	"c6 - Age in years"
label var	mrtcau	"c8 - Cause of death"
label var	mrtcau_o	"c8_o- If other cause of death is given, specify"
label var	mrtpid	"c_pid - deceased's pid"

save "$DataOUT\Mortality_Section_$VersionOUT.dta", replace			// saving out the dataset

* end of do file

*===========================================================================================================================================
